/*
 * Copyright (c) 2016 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShExpressFeeDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShExpressFeeService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShExpressFee;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShExpressFeeService 实现类
 * @author KongXiangyu
 * @since 2016-04-19
 */
@Service("shExpressFeeService")
public class ShExpressFeeServiceImpl extends BaseServiceImpl<ShExpressFee, Long> implements ShExpressFeeService {

    @Resource
    private ShExpressFeeDao shExpressFeeDao;

    public BaseDao<ShExpressFee, Long> getDao() {
        return shExpressFeeDao;
    }

	@Override
	public List<ShExpressFee> getDetailList(ShExpressFee expressFee) {
		return shExpressFeeDao.selectDetailList(expressFee);
	}

	@Override
	public ShExpressFee getDetailById(Long id) {
		if(id == null) {
			return null;
		}
		return shExpressFeeDao.selectDetailById(id);
	}

	@Override
	public DataGrid qeuryDataGrid(ShExpressFee expressFee, PageHelper page) {
		DataGrid grid = new DataGrid();

		int startIndex = (page.getPage() - 1) * page.getRows();
		int endIndex = page.getPage() * page.getRows();
		Integer count = shExpressFeeDao.selectEntryListCount(expressFee);
		grid.setTotal(count.longValue());

		if (grid.getTotal() > 0 && grid.getTotal() > startIndex) {
			expressFee.setStartIndex(startIndex);
			expressFee.setEndIndex(endIndex);
			if (!StringUtils.isBlank(page.getOrder())) {
				expressFee.setOrderFieldType(page.getOrder());
			}
			if (!StringUtils.isBlank(page.getSort())) {
				expressFee.setOrderField(page.getSort());
			}
			List<ShExpressFee> rows = shExpressFeeDao.selectDetailList(expressFee);
			grid.setRows(rows);
		}

		return grid;
	}

}